﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class RegulationDAL
    {
        #region [Regulation_Update]
        public bool Regulation_Update(DTO.RegulationDTO reg)
        {
            Connection connecttion = new Connection();
            MySqlConnection con = new MySqlConnection(connecttion.Connect);
            MySqlCommand cmd = new MySqlCommand("UpdateRegulation", con);
            cmd.CommandType = System.Data.CommandType.StoredProcedure;

            cmd.Parameters.Add(new MySqlParameter("@id", reg.RegulationID));
            cmd.Parameters.Add(new MySqlParameter("@regulation", reg.Content));

            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();

            return true;
        }
        #endregion

        #region[Regulation_SelectByID]
        public DTO.RegulationDTO Regulation_SelectByID(int id)
        {
            DTO.RegulationDTO reg = new DTO.RegulationDTO();
            Connection connecttion = new Connection();
            MySqlConnection con = new MySqlConnection(connecttion.Connect);
            MySqlCommand cmd = new MySqlCommand("SelectRegulationByID", con);
            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@regulationid", id);
            con.Open();
            MySqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                reg.RegulationID = dr.GetInt32(0);
                reg.Content = dr.GetString(1);
            }
            dr.Close();
            con.Close();
            return reg;
        }
        #endregion
    }
}
